/** 
  * @file		app_mqtt.c
  * @author		周晨
  * @version	V1.0.0
  * @date		24/1/2024
  * @brief		远程报警实验-mqtt
  * @par 描述:
  *         mqtt连接
 */

/**
  * @brief 头文件 
 */
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "mqtt.h"

/** 串口输入任务 **/
void Mqtt_task(void)
{
    mqtt_msg app_mqtt_opts;
    app_mqtt_opts.clientid = "mqtt_clientid_0";
    app_mqtt_opts.username = NULL;
    app_mqtt_opts.password = NULL;
    app_mqtt_opts.host = "139.159.235.171";
    app_mqtt_opts.subscriber = "N_send";
    app_mqtt_opts.port = 1883;

    Network_mqtt_connect(app_mqtt_opts);
}

/** 串口任务创建函数 **/
void Mqtt_entry(void)
{
    usleep(12*1000*1000);  //延时12S,等待系统启动及网络连接

    osThreadAttr_t attr;  //任务属性的结构体

    attr.name = "Mqtt_task";   //任务名称
    attr.stack_size = 8*1024;  //任务的内存大小
    attr.priority = 25;        //任务的优先级
    //创建任务
    if (osThreadNew((osThreadFunc_t)Mqtt_task, NULL, &attr) == NULL) 
    {
        //任务创建失败
        printf("  Failed to create Mqtt_task!\r\n");
    }
    //任务创建成功
    printf("\n  Succeed to create Mqtt_task!\r\n");
}

/** 让系统运行指定的函数 **/
SYS_RUN(Mqtt_entry);